package ams.interceptor;

import java.util.List;
import java.util.Map;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

import ams.util.SysConstans;

public class LoginInterceptor extends AbstractInterceptor {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		Map<String, Object> session = ActionContext.getContext().getSession();
		Boolean isLogin = (Boolean)session.get(SysConstans.SESSION_LOGIN_ACCOUNT);
		@SuppressWarnings("unchecked")
		List<String> urlList = (List<String>)session.get(SysConstans.SESSION_URL_LIST);
		if(isLogin == null){
			return "login";
		}
		String currentUrl = ServletActionContext.getRequest().getRequestURI();
		if(!urlList.contains(currentUrl)){
			return "deny";
		}
		invocation.invoke();
		return null;
	}

}
